package com.ytjj.qmyx.mall.controller.h5;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.controller.BaseController;
import com.ytjj.common.service.RedisService;
import com.ytjj.qmyx.mall.enums.ActivityTypeEnums;
import com.ytjj.qmyx.mall.model.response.ActivityProductResponse;
import com.ytjj.qmyx.mall.service.ActivityService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * 会员特卖活动
 *
 **/
@RestController
@RequestMapping("/h5/membersale")
public class H5MemberSaleController extends BaseController {
    @Resource
    private ActivityService activityService;

    @Resource
    private RedisService redisService;
    /**
     * 栏目商品列表
     *
     * @return
     */
    @GetMapping("/queryListByPage")
    public CommonResult queryListByPage(@RequestParam(value = "columnId", required = false, defaultValue = "0") Integer columnId,
                                                 @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                                 @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                 @RequestParam(value = "flag", required = false, defaultValue = "0") Integer flag) {

        List<ActivityProductResponse> productList = activityService.getActivityList(pageNum, pageSize,ActivityTypeEnums.MEMBER_SALE.name(),columnId);
        if(1==flag){//打乱顺序
            Collections.shuffle(productList);
        }
        return CommonResult.success(productList);
    }
}
